//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.zaicheng.cloud.remotecall.template;

import java.util.Optional;
import java.util.regex.Pattern;

abstract class Expression implements TemplateChunk {
    private String name;
    private Pattern pattern;

    Expression(String name, String pattern) {
        this.name = name;
        Optional.ofNullable(pattern).ifPresent((s) -> {
            this.pattern = Pattern.compile(s);
        });
    }

    abstract String expand(Object var1, boolean var2);

    public String getName() {
        return this.name;
    }

    Pattern getPattern() {
        return this.pattern;
    }

    boolean matches(String value) {
        return this.pattern == null ? true : this.pattern.matcher(value).matches();
    }

    @Override
    public String getValue() {
        return this.pattern != null ? "{" + this.name + ":" + this.pattern + "}" : "{" + this.name + "}";
    }

    @Override
    public String toString() {
        return this.getValue();
    }
}
